package com.cocolove2.library_cocodialog.dialogs;

import android.content.Context;
import android.graphics.Color;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.cocolove2.library_cocodialog.dialogs.base.CocoAlertDialogBase;
import com.cocolove2.library_cocodialog.CornerUtils;

@SuppressWarnings({"unused"})
public class NormalCocoDialog extends CocoAlertDialogBase<NormalCocoDialog> {
    //默认button的高度
    final static int DEFAULT_BUTTON_HEIGHT = 45;
    /**
     * title underline
     */
    private View mVLineTitle;
    /**
     * vertical line between btns
     */
    private View mVLineVertical;
    /**
     * vertical line between btns
     */
    private View mVLineVertical2;
    /**
     * horizontal line above btns
     */
    private View mVLineHorizontal;
    /**
     * title underline color(标题下划线颜色)
     */
    private int mTitleLineColor = Color.parseColor("#61AEDC");
    /**
     * title underline height(标题下划线高度)
     */
    private float mTitleLineHeight = 1f;
    /**
     * btn divider line color(对话框之间的分割线颜色(水平+垂直))
     */
    private int mDividerColor = Color.parseColor("#DCDCDC");


    public NormalCocoDialog(Context context) {
        super(context);

        /** default value*/
        mTitleTextColor = Color.parseColor("#61AEDC");
        mTitleTextSize = 22f;
        mMessageTextColor = Color.parseColor("#383838");
        mMessageTextSize = 17f;

        mBtnNegativeTextColor = Color.parseColor("#8a000000");
        mBtnPositiveTextColor = Color.parseColor("#8a000000");
        mBtnNeutralTextColor = Color.parseColor("#8a000000");
        /** default value*/
    }

    @Override
    protected View onCreateView(Context context, ViewGroup parent) {
        /** title */
        mLlContainer.addView(mTvTitle);
        /** title underline */
        mVLineTitle = new View(mContext);
        mLlContainer.addView(mVLineTitle);
        /** content */
        mLlContainer.addView(mTvMessage);

        mVLineHorizontal = new View(mContext);
        mVLineHorizontal.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 1));
        mLlContainer.addView(mVLineHorizontal);

        /** btns */
        mTvBtnNegative.setLayoutParams(new LinearLayout.LayoutParams(0, dp2px(DEFAULT_BUTTON_HEIGHT), 1));
        mLlBtns.addView(mTvBtnNegative);

        mVLineVertical = new View(mContext);
        mVLineVertical.setLayoutParams(new LinearLayout.LayoutParams(1, LinearLayout.LayoutParams.MATCH_PARENT));
        mLlBtns.addView(mVLineVertical);

        mTvBtnNeutral.setLayoutParams(new LinearLayout.LayoutParams(0, dp2px(DEFAULT_BUTTON_HEIGHT), 1));
        mLlBtns.addView(mTvBtnNeutral);

        mVLineVertical2 = new View(mContext);
        mVLineVertical2.setLayoutParams(new LinearLayout.LayoutParams(1, LinearLayout.LayoutParams.MATCH_PARENT));
        mLlBtns.addView(mVLineVertical2);

        mTvBtnPositive.setLayoutParams(new LinearLayout.LayoutParams(0, dp2px(DEFAULT_BUTTON_HEIGHT), 1));
        mLlBtns.addView(mTvBtnPositive);

        mLlContainer.addView(mLlBtns);

        return mLlContainer;
    }


    @Override
    protected void setupUiView() {
        super.setupUiView();
        /** title underline */
        if (mTitle != null) {
            mVLineTitle.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    dp2px(mTitleLineHeight)));
            mVLineTitle.setBackgroundColor(mTitleLineColor);
            mVLineTitle.setVisibility(View.VISIBLE);
        } else {
            mVLineTitle.setVisibility(View.GONE);
        }

        /** btns */
        mVLineHorizontal.setBackgroundColor(mDividerColor);
        mVLineVertical.setBackgroundColor(mDividerColor);
        mVLineVertical2.setBackgroundColor(mDividerColor);

        if (mBtnNeutralText == null && mBtnPositiveText == null && mBtnNegativeText == null) {
            mVLineHorizontal.setVisibility(View.GONE);
            mVLineVertical.setVisibility(View.GONE);
            mVLineVertical2.setVisibility(View.GONE);
            mTvBtnNeutral.setVisibility(View.GONE);
            mTvBtnNegative.setVisibility(View.GONE);
            mTvBtnPositive.setVisibility(View.GONE);
        } else if (mBtnPositiveText == null || mBtnNegativeText == null) {
            mTvBtnNegative.setVisibility(View.GONE);
            mTvBtnPositive.setVisibility(View.GONE);
            mVLineVertical.setVisibility(View.GONE);
            mVLineVertical2.setVisibility(View.GONE);
        } else if (mBtnNeutralText == null) {
            mVLineVertical.setVisibility(View.GONE);
            mTvBtnNeutral.setVisibility(View.GONE);
        }

        /**set background color and corner radius */
        mLlContainer.setBackground(CornerUtils.cornerDrawable(mDialogBgColor, mCornerRadius));

        mTvBtnNegative.setBackground(CornerUtils.btnSelector(mCornerRadius, mDialogBgColor, mBtnPressColor, 0));
        mTvBtnPositive.setBackground(CornerUtils.btnSelector(mCornerRadius, mDialogBgColor, mBtnPressColor, 1));
        mTvBtnNeutral.setBackground(CornerUtils.btnSelector(mBtnPositiveText == null || mBtnNegativeText == null ?
                mCornerRadius : 0, mDialogBgColor, mBtnPressColor, -1));
    }


    /**
     * set title underline color(设置标题下划线颜色)
     */
    public NormalCocoDialog setTitleLineColor(int titleLineColor) {
        this.mTitleLineColor = titleLineColor;
        return this;
    }

    /**
     * set title underline height(设置标题下划线高度)
     */
    public NormalCocoDialog setTitleLineHeight(float titleLineHeight_DP) {
        this.mTitleLineHeight = titleLineHeight_DP;
        return this;
    }

    /**
     * set divider color between btns(设置btn分割线的颜色)
     */
    public NormalCocoDialog setDividerColor(int dividerColor) {
        this.mDividerColor = dividerColor;
        return this;
    }
}
